home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 24
/
Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso
/
Aminet
/
biz
/
dbase
/
Aminet2DB.lha
/
TSV2CSV.rexx
< prev
Wrap
OS/2 REXX Batch file
|
1998-01-28
|
1KB
|
50 lines
/*
* TSV2CSV.rexx
* Converts tab-separated values to comma-separated values.
* $VER: TSV2CSV.rexx 1.0 (6.12.97)
* By Deok-Min Yun
*/
OPTIONS RESULTS
PARSE ARG filename
tab = '09'x
IF OPEN('DataFile', filename, 'R') = 1 THEN DO
IF OPEN('SaveFile', filename||'.CSV', 'W') = 1 THEN DO
DO FOREVER
temp = READLN('DataFile')
IF EOF('DataFile') THEN BREAK
ptr = 1; quote_used = 0
temp = TRANSLATE(temp, "'", '"')
DO WHILE INDEX(temp, tab, ptr) ~= 0
tab_pos = INDEX(temp, tab, ptr)
IF (tab_pos ~= 0) THEN DO
ptr = tab_pos
IF quote_used = 1 THEN DO
temp = INSERT('"', temp, ptr)
quote_used = 0
ptr = ptr + 1
END
comma = INDEX(temp, ',', ptr)
tab_pos2 = INDEX(temp, tab, ptr + 1)
IF (tab_pos2 = 0 & comma ~= 0) | (comma ~= 0 & comma < tab_pos2) THEN DO
quote_used = 1
END
temp = OVERLAY(',', temp, ptr)
IF quote_used = 1 THEN DO
temp = INSERT('"', temp, ptr)
ptr = ptr + 1
END
END
END
IF quote_used = 1 THEN temp = INSERT('"', temp, LENGTH(temp))
CALL WRITELN('SaveFile', temp)
END
CALL CLOSE('SaveFile')
END
ELSE SAY "Couldn't create a new file."
CALL CLOSE('DataFile')
END
ELSE SAY "Couldn't open original file."